package tool.lib;


import tool.lib.entity.BirthBean;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;

public class EncryptTool {

	public static String getMD5(String val)  {
		String result = "";
		MessageDigest md;
		try {
			md = MessageDigest.getInstance("MD5");
			md.update(val.getBytes());
			byte b[] = md.digest();
			int i;
			StringBuffer buf = new StringBuffer("");
			for (int offset = 0; offset < b.length; offset++) {
				i = b[offset];
				if (i < 0)
					i += 256;
				if (i < 16)
					buf.append("0");
				buf.append(Integer.toHexString(i));
			}
			result = buf.toString();
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
    public static String getRandomVerity()
    {
        Random random= new Random();
        return  (random.nextInt(900000)+100000)+"";
    }
	public static BirthBean parseBirthday(String birthday)
	{
		BirthBean bean=new BirthBean();
		String[] array=birthday.split("-");
		bean.setYear(Integer.parseInt(array[0]));
		bean.setMonth(Integer.parseInt(array[1]));
		bean.setDay(Integer.parseInt(array[2]));
		return  bean;
	}
}
